/**
 * 
 */
package com.moon.jy.util;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

/**
 * 完整退出程序
 * url：http://www.cnblogs.com/qingblog/archive/2012/06/08/2541790.html
 * @author paul.gaol
 * @date 2014-3-23
 */
public class ExitApplication extends Application {
    private List<Activity>         activityList = new LinkedList<Activity>();

    private static ExitApplication instance;

    private ExitApplication() {
    }

    //单例模式中获取唯一的ExitApplication 实例
    public static ExitApplication getInstance() {
        if (null == instance) {
            instance = new ExitApplication();
        }
        return instance;

    }

    //添加Activity 到容器中
    public void addActivity(Activity activity) {
        activityList.add(activity);
    }

    //遍历所有Activity 并finish

    public void exit() {

        for (Activity activity : activityList) {
            activity.finish();
        }

        System.exit(0);

    }
}
